package cn.itcast.service.impl;

import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.mapper.CompanyMapper;
import cn.itcast.pojo.Company;
import cn.itcast.service.CompanyService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyMapper companyMapper;

    //查询所有的公司地址
    public List<Company> findAll() {
        return companyMapper.findAll();
    }

    //分页查询公司地址
    public PageResult findPage(QueryPageBean queryPageBean) {
        //设置分页查询的参数
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //查询所有的数据
        List<Company> list = companyMapper.findByCondition(queryPageBean.getQueryString());

        PageInfo<Company> pageInfo = new PageInfo<>(list);

        return new PageResult(pageInfo.getTotal(),list);
    }

    //添加公司地址
    public void add(Company company) {
        companyMapper.add(company);
    }

    //根据公司id删除地址
    public void deleteById(int id) {
        companyMapper.deleteById(id);
    }

    //根据公司地址查询公司
    public Company findByAddress(String address_name) {
        return companyMapper.findByAddress(address_name);
    }
}
